<template>
	<m-layout title="我的代理商品" gap="24">
		<template v-for="(item, index) in listArr">
			<m-block gap="16 20" spa="0 0 16">
				<view class="li flex ai-flex-start" @click="Jump('/pages/home/goodsDetail/goodsDetail?id=' + item.gid)">
					<m-image2 radius="12" :src="item.picurl" :size="[100,110]" />
					<text class="ml-12 fs26">{{item.gname}}</text>
				</view>
			</m-block>
		</template>
		<m-loading gap="40 0" :list="listArr" :pageIndex="pageIndex" :pageCount="pageCount" :loading="isLoading" />
	</m-layout>
</template>

<script>
	import { mygoodsdls } from '@/api/Goods.js';
	export default {
		data() {
			return {
				listArr: [],
				pageIndex: 1,
				pageSize: 10,
				pageCount: 1,
				isLoading: true
			};
		},
		watch: {
			tabIdx() {
				this.reset();
			}
		},
		onLoad() {
			this.reset();
		},
		methods: {
			// 初始化
			reset() {
				this.pageCount = 1;
				this.pageIndex = 1;
				this.getData();
			},
			// 获取用户兑换申请数据
			async getData() {
				if (this.pageIndex > this.pageCount) {
					return;
				}
				this.isLoading = true;
				const { pageCount, list, success } = await mygoodsdls({
					PageIndex: this.pageIndex,
					PageSize: this.pageSize
				});
				this.isLoading = false;
				this.pageCount = pageCount;
				console.log('list', list)
				if (this.pageIndex <= 1) {
					this.listArr = list;
				} else {
					this.listArr = [...this.listArr, ...list];
				}
				this.pageIndex++;
				uni.stopPullDownRefresh();
			}
		},
		onPullDownRefresh() {
			this.reset();
		},
		onReachBottom() {
			this.getData();
			console.log('触底了');
		}
	};
</script>

<style lang="scss">
	.li {
		
	}
</style>